#include <stdio.h>
#include "freertos/FreeRTOS.h"

#include "s3.h"
#include "lv_demos.h"

static const char *TAG = "main";

/* Import music file as buffer */
extern const uint8_t music_pcm_start[] asm("_binary_canon_pcm_start");
extern const uint8_t music_pcm_end[] asm("_binary_canon_pcm_end");

void app_main(void)
{
	i2c_init();
	PCA9557_Init();
	lcd_init();
	lcd_touch_init();
	// camera_init();
	// sd_init();
	i2s_driver_init();
	es8311_codec_init();

	size_t bytes_write = 0;
	uint8_t *data_ptr = (uint8_t *)music_pcm_start;

	/* (Optional) Disable TX channel and preload the data before enabling the TX channel,
	 * so that the valid data can be transmitted immediately */
	ESP_ERROR_CHECK(i2s_channel_disable(tx_handle));
	ESP_ERROR_CHECK(i2s_channel_preload_data(tx_handle, data_ptr, music_pcm_end - data_ptr, &bytes_write));
	data_ptr += bytes_write; // Move forward the data pointer

	/* Enable the TX channel */
	ESP_ERROR_CHECK(i2s_channel_enable(tx_handle));
	i2s_channel_write(tx_handle, data_ptr, music_pcm_end - data_ptr, &bytes_write, portMAX_DELAY);
	ESP_LOGI(TAG, "Hello world!");
	// lv_start();
	// lv_demo_benchmark();
	// lv_demo_widgets();
	while (1)
	{
		// camera_capture();
		printf("Hello world!\n");
		vTaskDelay(2000 / portTICK_PERIOD_MS);
	}
}
